########################################################################
# about.py - Defines About GUI dialog for DDUP
#
# Created 2006.09.11 by Rick Barrett
#
# Copyright (c) 2006 by Pixel Corps.  This program may be used under
# the terms of the X11 license, a copy of which should have accompanied
# this program, in the LICENSE file.
########################################################################

import localparms, util

import wx

import os


#### class AboutDialog #################################################


class AboutDialog(wx.Dialog):
	""" 
	Class defining the DDUP About dialog layout
	""" 
	def __init__(self, mainframe):
		wx.Dialog.__init__(self, mainframe, wx.ID_ANY, 
			"Wick Digital Dailies Uploader")

		# Create wx.Stuff everything else rests on
		self.panel = wx.Panel(self)
		self.mainSizer = wx.BoxSizer(wx.VERTICAL)
		
		# Add version text
		versionText = "Version " + localparms.parms.getVersion() + \
			"\nCopyright " + u"\xa9 " + "2006 Pixel Corps"
		self.aboutText = wx.StaticText(self.panel, wx.ID_ANY,
					versionText, style = wx.ALIGN_LEFT)
		
		try:
			fLic = file(util.FindAppResource("license.txt"))
			licenseText = fLic.read()
			fLic.close()
		except:
			licenseText = "See http://wickdd.org/license.html " + \
					"for license info."
		
		self.licenseSizer = wx.StaticBoxSizer(
				wx.StaticBox(self.panel, wx.ID_ANY, 'License'),
				wx.VERTICAL)
		self.licenseTextCtrl = wx.TextCtrl(self.panel, wx.ID_ANY, licenseText,
					size = tuple([480, 300]),
					style = wx.TE_MULTILINE | wx.TE_READONLY)
		self.licenseSizer.Add(self.licenseTextCtrl, flag = wx.ALIGN_CENTER)
		
		# Add branding image to dialog
		self.brandImageSizer = util.GetBanner(self.panel,
				self.licenseSizer)
		
		# Add buttons
		self.buttonSizer = wx.GridSizer(cols = 1,
				hgap = 10, vgap = 5)
		self.closeButton = wx.Button(self.panel, wx.ID_CANCEL, "Close")
		self.closeButton.SetDefault()
		self.buttonSizer.Add(self.closeButton, flag = wx.ALIGN_CENTER)
		
		# Add Sizers to mainSizer
		self.mainSizer.Add(self.brandImageSizer, flag = wx.ALL,
				border = 10)
		self.mainSizer.Add(self.aboutText, flag = wx.ALL, border = 10)
		self.mainSizer.Add(self.licenseSizer, flag = wx.ALL, border = 10)
		self.mainSizer.Add(self.buttonSizer, flag = wx.ALL | wx.EXPAND,
				border = 10)

		# Add and format panel
		self.panel.SetSizer(self.mainSizer)
		self.mainSizer.Fit(self)
		self.mainSizer.SetSizeHints(self)
		self.Center()

		# Set up event bindings
		self.licenseTextCtrl.Bind(wx.EVT_CHAR, self.OnCharacter)


	def OnCharacter(self, event):
		if event.CmdDown() and event.GetKeyCode() == ord('w'):
			self.Close()
		else:
			event.Skip()
